const jwt = require("jsonwebtoken");
const {SECRET} = require('../config/config')
module.exports = (req, res, next) => {
  const token = req.get("token");
  if (!token) {
    return res.json({
      code: 400,
      msg: "未进行登录",
      data: null,
    });
  }
  jwt.verify(token, SECRET, (err, res) => {
    if (err) {
      return res.json({
        code: 400,
        msg: "无效token",
        data: null,
      });
    }
    req.user = res
    next();
  });
};
